package diploma.kisel.modelas.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Domain class for Workplace (table - workplace).
 * 
 * @author Nikolay Kisel
 *
 */
@Entity
@Table(name = "workplace")
@NamedQueries({
		@NamedQuery(name = "Workplace.findAll", query = "select w from Workplace w"),
		@NamedQuery(name = "Workplace.findById", query = "select w from Workplace w where w.id = :id") })
public class Workplace {

	private Integer id;
	private String number;
	private UserType userType;
	private Integer countApp;
	private Integer countDb;

	// for many to many mapping
	private Set<Program> programs = new HashSet<Program>();
	private Set<Application> applications = new HashSet<Application>();
	private Set<Workstation> workstations = new HashSet<Workstation>();
	private Set<Database> localDatabases = new HashSet<Database>();

	public Workplace() {

	}

	public Workplace(String number, UserType userType) {
		this.number = number;
		this.userType = userType;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id_workplace")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "number")
	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	@Column(name = "user_type")
	@Enumerated(EnumType.STRING)
	public UserType getUserType() {
		return userType;
	}

	public void setUserType(UserType userType) {
		this.userType = userType;
	}

	@Column(name = "count_application")
	public Integer getCountApp() {
		return countApp;
	}

	public void setCountApp(Integer countApp) {
		this.countApp = countApp;
	}

	@Column(name = "count_db")
	public Integer getCountDb() {
		return countDb;
	}

	public void setCountDb(Integer countDb) {
		this.countDb = countDb;
	}

	@ManyToMany
	@JoinTable(name = "list_program", joinColumns = @JoinColumn(name = "id_workplace"), inverseJoinColumns = @JoinColumn(name = "id_program"))
	public Set<Program> getPrograms() {
		return programs;
	}

	public void setPrograms(Set<Program> program) {
		this.programs = program;
	}

	@ManyToMany
	@JoinTable(name = "list_application", joinColumns = @JoinColumn(name = "id_workplace"), inverseJoinColumns = @JoinColumn(name = "id_application"))
	public Set<Application> getApplications() {
		return applications;
	}

	public void setApplications(Set<Application> applications) {
		this.applications = applications;
	}

	@ManyToMany
	@JoinTable(name = "list_workplace", joinColumns = @JoinColumn(name = "id_workplace"), inverseJoinColumns = @JoinColumn(name = "id_workstation"))
	public Set<Workstation> getWorkstations() {
		return workstations;
	}

	public void setWorkstations(Set<Workstation> workstations) {
		this.workstations = workstations;
	}	

	@ManyToMany
	@JoinTable(name = "list_ldb", joinColumns = @JoinColumn(name = "id_workplace"), inverseJoinColumns = @JoinColumn(name = "id_database"))
	public Set<Database> getLocalDatabases() {
		return localDatabases;
	}

	public void setLocalDatabases(Set<Database> localDatabases) {
		this.localDatabases = localDatabases;
	}

	@Override
	public String toString() {
		return "Workplace [id=" + id + ", number=" + number + ", userType="
				+ userType + "]";
	}

}
